package com.biz.primus.homepage.vo;


import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.homepage.enums.TimeRangePolicy;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by jiangnan on 2017/7/12.
 */
@Data
public class ProgramRoVo implements Serializable {

    private Long id;

    private String coverId;

    private Long parentId;

    private String sourceId;

    private String dataJson;

    private String description;

    private String name;

    private CommonStatus status = CommonStatus.ENABLE;

    private TimeRangePolicy timeRangePolicy = TimeRangePolicy.INHERIT;

    /**
     * 开始时间
     */
    private Date startTime;

    /**
     * 结束时间
     */
    private Date endTime;

    private ProgramRoVo parent;

    /**
     * 是否在有效时间内
     */
    public boolean atTheRightTime() {

        if (timeRangePolicy == TimeRangePolicy.INHERIT && parent != null) {
            return (parent.atTheRightTime());
        } else {
            long currentTimeMillis = System.currentTimeMillis();
            return startTime != null && endTime != null && currentTimeMillis >= startTime.getTime() && System.currentTimeMillis() <= endTime.getTime();
        }
    }

}
